/*
 * Copyright (C) 2011, EADS France
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 */
package xowl.interpreter.backends.rdf;

import java.util.HashMap;
import java.util.Map;

/**
 *
 * @author Laurent WOUTERS
 */
public abstract class TranslatorRDF_Rule {
    protected int priority;
    protected Map<String, XOWLVariableNode> variables;

    public int getPriority() { return priority; }
    
    public TranslatorRDF_Rule(int priority) {
        this.priority = priority;
        this.variables = new HashMap<String, XOWLVariableNode>();
    }
    
    protected XOWLVariableNode getVar(String name) {
        if (variables.containsKey(name))
            return variables.get(name);
        xowl.lang.actions.QueryVariable qvar = new xowl.lang.actions.QueryVariable();
        qvar.setName(name);
        XOWLVariableNode var = new XOWLVariableNode(qvar);
        variables.put(name, var);
        return var;
    }
    protected RDFNode getValue(Map<XOWLVariableNode, RDFNode> bindings, String name) {
        return bindings.get(variables.get(name));
    }
    
    public abstract RDFTriple[] getPatterns();
    public abstract void activate(Map<XOWLVariableNode, RDFNode> bindings);
}
